#include "ObjectLoader.h"
//using namespace std;

// Loads objects from a text file and stores them
void ObjectLoader::LoadObjects(std::vector<Colider*>& objectStorage)
{
	std::string modelType;
	float x, y, z, w, xs, ys, zs;

	std::ifstream reader;
	reader.open(ObjectFile);
	std::string data;

	if(reader.is_open())
	{
		while(getline (reader, data), !reader.eof())
		{
			// Skip Descriptions
			getline ( reader, data, ',' );

			// Model
			getline ( reader, data, ',' );
			modelType = data;

			// Location
			getline ( reader, data, ',' );
			x = atof(data.c_str());

			getline ( reader, data, ',' );
			y = atof(data.c_str());

			getline ( reader, data, ',' );
			z = atof(data.c_str());

			// Mass
			getline ( reader, data, ',' );
			w = atof(data.c_str());

			// Scale
			getline ( reader, data, ',' );
			xs = atof(data.c_str());

			getline ( reader, data, ',' );
			ys = atof(data.c_str());

			getline ( reader, data, ',' );
			zs = atof(data.c_str());

			Colider * tempObject = new Colider(GameConstants::MODELS[modelType], Vector3<float>(x, y, z), w, Quaternion::NO_ROTATION, Vector3<float>(xs, ys, zs));

			//Colider tempObject(GameConstants::MODELS[modelType], Vector3<float>(x, y, z), w);
			//tempObject.Scale() = Vector3<float>(x, y, z);

			// Color
			getline ( reader, data, ',' );
			x = atof(data.c_str());

			getline ( reader, data, ',' );
			y = atof(data.c_str());

			getline ( reader, data, ',' );
			z = atof(data.c_str());

			getline ( reader, data, ',' );
			w = atof(data.c_str());
			
			tempObject->_color = MyColor(x, y, z, w);

			objectStorage.push_back(tempObject);
		}
	}

	reader.close();

}

/*
Colider floor(GameConstants::MODELS["Cube"], Vector3<float>(0,-10,0), 20);
floor.Scale() = Vector3<float>(1000,2,1000);
floor._color = MyColor(1,0,0,1);


Colider b1(GameConstants::MODELS["Cube"], Vector3<float>(-100,48,5), 20);
b1.Scale() = Vector3<float>(10,100,10);
b1._color = MyColor(0,0,1,1);

Colider b2(GameConstants::MODELS["Cube"], Vector3<float>(20,3,100), 20);
b2.Scale() = Vector3<float>(10,10,10);
b2._color = MyColor(0,1,0,1);

Colider p1(GameConstants::MODELS["Pirmid"], Vector3<float>(20,8,-100), 20);
p1.Scale() = Vector3<float>(20,20,20);
p1._color = MyColor(1,1,0,1);

_objects.push_back(floor);
_objects.push_back(b1);
_objects.push_back(b2);
_objects.push_back(p1);
*/